package com.qianfeng.xiaxk.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.qianfeng.xiaxk.R;
import com.qianfeng.xiaxk.activity.SettingActivity;


/**
 */
public class MineFragment extends Fragment implements View.OnClickListener {
    ActionBar actionBar;
    View actionBarView;
    public static MineFragment newInstance(String param1, String param2) {
        MineFragment fragment = new MineFragment();
        return fragment;
    }

    public MineFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
    private void initActionBarView() {
        AppCompatActivity activity = (AppCompatActivity)getActivity();
        actionBar = activity.getSupportActionBar();
        actionBar = ((AppCompatActivity)getActivity()).getSupportActionBar();
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.show();
        LinearLayout layout = new LinearLayout(getActivity());
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,      ViewGroup.LayoutParams.WRAP_CONTENT);
        layout.setLayoutParams(lp);
        actionBarView = activity.getLayoutInflater().inflate(R.layout.actionbar_setting, null);
        actionBarView.findViewById(R.id.chat_setting).setOnClickListener(this);
        actionBar.setCustomView(actionBarView);

    }
    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if(!hidden){///显示的
            if(actionBarView==null || actionBar==null){
                initActionBarView();
            }
            actionBar.show();
        }
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_mine, container, false);
    }


    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.chat_setting:
                startActivity(new Intent(getActivity(), SettingActivity.class));
                break;
        }
    }
}
